package com.heima.xiyuanmall.sudoku.sample

import android.annotation.SuppressLint
import android.os.Handler
import android.os.Message
import android.view.View
import com.heima.xiyuanmall.sudoku.CellStyle
import com.heima.xiyuanmall.sudoku.Pos
import com.heima.xiyuanmall.sudoku.RenderEventsHolder
import com.heima.xiyuanmall.sudoku.StyleRenderer

/**
 * @author flutterdash@qq.com
 * @since 2021/10/3 23:34
 */
class KotlinSample {

    lateinit var handler: Handler

    fun onCreate() {
        handler = ViewRenderer()
    }

    @SuppressLint("HandlerLeak")
    inner class ViewRenderer : Handler() {
        override fun handleMessage(msg: Message) {
            val holder = msg.obj
            if (holder is RenderEventsHolder) {
                renderView(holder.events)
            }
        }

        private fun renderView(events: Collection<CellStyle>) {
            fun render(view: View, renderer: StyleRenderer) = renderer.render(view)
            for (event in events) {
                render(getView(event.pos), event.renderer)
            }
        }

        /**
         * @param pos 数独表格上的一个坐标
         * @return    根据这个坐标返回对应单元格的View对象
         */
        private fun getView(pos: Pos): View = TODO()
    }
}